home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 7.3 KB | 287 lines | [TEXT/MPS ] |
- /*
- File: CDSSpec
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <3> 10/14/94 TMH added CDSSpec constructor
- <2> 9/27/94 TMH added CUnpackedDSSpec assignment operator
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- <2> 9/9/94 TMH added constructor to CUnpackedDSSpec
- 6/10/94 TMH xxx put comment here xxx
-
- To Do:
- */
-
- #ifndef __STDIO__
- #include "StdIO.h"
- #endif
-
- #ifndef __CDSSpec__
- #include "CDSSpec.h"
- #endif
-
- #ifndef __PMSAMResourceIds__
- #include "PMSAMResourceIds.h"
- #endif
-
- #ifndef __PMSAMResources__
- #include "PMSAMResources.h"
- #endif
-
-
-
- //----------------------------------------
- // C U n p a c k e d D S S p e c
- //----------------------------------------
-
-
- //--------------------------------------------------------------------------
- CUnpackedDSSpec& CUnpackedDSSpec::operator =(OCEPackedRecipient* packedRecipient)
- {
- OCEUnpackDSSpec((PackedDSSpec*)packedRecipient,(DSSpec*)this,fEntitySpecifier);
- return *this;
- };
-
- //--------------------------------------------------------------------------
- CUnpackedDSSpec::CUnpackedDSSpec(OCEPackedRecipient* packedRecipient)
- {
- fEntitySpecifier = &fEntity;
- OCEUnpackDSSpec((PackedDSSpec*)packedRecipient,(DSSpec*)this,fEntitySpecifier);
-
- }
-
- //--------------------------------------------------------------------------
- // for decodeing dialup phone number string
- struct UnpackedPhAddr {
- short viewType;
- Str31 CC;
- Str31 AC;
- Str31 phNum;
- Str31 postfix;
- char directDial[128];
- };
- #ifndef __cplusplus
- typedef struct UnpackedPhAddr UnpackedPhAddr;
- #endif
-
- #define InlineCode(selector) = { 0x303C, selector, 0xAA5C}
- #define sDialupUnpackPhAddr 1282
- pascal Boolean DialupUnpackPhAddr(RString* RSPtr, UnpackedPhAddr* ph) InlineCode(sDialupUnpackPhAddr);
-
- #define kTemplateView 1
- #define kIKnowView 2
-
-
- //--------------------------------------------------------------------------
- StringPtr CUnpackedDSSpec::ExtValue(short asType, Ptr buffer)
- {
- CDirExtTypeTableIterator iter(kDirExtTypeTableID);
- StringPtr otherRecipient = (StringPtr)buffer;
-
- DirExtTypeEntry* defaultDirExtType = 0;
-
- otherRecipient[0] = 0;
-
- for( DirExtTypeEntry* dirExtType = iter.FirstDirExtType();iter.More(); dirExtType = iter.NextDirExtType() ) {
-
- defaultDirExtType = dirExtType;
-
- if( fExtType == dirExtType->extType ) {
-
- if( dirExtType->isRString )
- otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P", &dirExtType->dirSysName, ExtValue() );
- else
- {
- switch (fExtType)
- {
- case 'entn':
- otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P",&dirExtType->dirSysName, (StringPtr)EntityName());
- break;
-
- case 'aphn':
- UnpackedPhAddr upPhone;
-
- if (DialupUnpackPhAddr((RString *)fExtValue, &upPhone))
- {
- if (upPhone.viewType == kTemplateView)
- otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P%P%P",&dirExtType->dirSysName,
- (StringPtr)upPhone.CC, (StringPtr)upPhone.AC, (StringPtr)upPhone.phNum);
- else
- otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P",&dirExtType->dirSysName,
- (StringPtr)upPhone.directDial);
- }
-
- break;
-
- case 'TFAX':
-
- // this is what I think the TFAX extension compound rstring format is:
- // long - not used, usually 0 (0 length rstring???)
- // RString - country code
- // RString - area code
- // RString - phone number
-
-
- // skip the first unused long, move the point to the body of ext value rstring where the first rstring is
- Ptr ext = (Ptr)fExtValue;
- ext = (Ptr)&(((RStringPtr)ext) -> body[0]);
- StringPtr cc,ac,ph;
-
- cc = OCERToPString((RStringPtr)ext);
-
- // point to next rstring
- ext = ext+ ((RStringPtr)ext) -> dataLength + sizeof(ProtoRString);
- if (cc[0] % 2) // odd number string, skip the padding
- ext += 1;
-
- ac = OCERToPString((RStringPtr)ext);
-
- // point to next rstring
- ext = ext+ ((RStringPtr)ext) -> dataLength + sizeof(ProtoRString);
- if (ac[0] % 2) // odd number string, skip the padding
- ext += 1;
-
- ph = OCERToPString((RStringPtr)ext);
-
- // put them in buffer
- otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P%P%P",&dirExtType->dirSysName,
- (StringPtr)cc, (StringPtr)ac, (StringPtr)ph);
- break;
-
- default:
- break;
- }
- }
- break;
-
- }
-
- }
-
- // ASSERT(defaultDirExtType);
-
- if( (defaultDirExtType!=0) && (otherRecipient[0] == 0) ) {
- // ASSERTPRINT(false,("MapOtherAddress unknown extType %.4s\n",&unpackedRecipient.fExtType) );
- otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P",&defaultDirExtType->dirSysName, (StringPtr)EntityName());
-
- }
-
-
- return otherRecipient;
-
- }
-
- //--------------------------------------------------------------------------
- StringPtr CUnpackedDSSpec::ExtValue()
- {
-
- switch(fExtType) {
- case 'alan':
- return (StringPtr)fExtValue;
- case 'entn': {
- CUnpackedDSSpec mailServer((OCEPackedRecipient*)(fExtValue + sizeof(OSType)));
- return mailServer.EntityName();
- }
- default:
- return (StringPtr) *(CRString*)fExtValue; // assume its an RString
- }
-
- }
-
-
-
-
- //---------------------------------
- // C D S S p e c
- //---------------------------------
-
- // some of these may not be used anymore.
-
- //-------------------------------------------------------------------------------------------
- CDSSpec::CDSSpec(StringPtr name,StringPtr dirName, OSType extType,StringPtr extValue )
- {
- fExtValue = (Ptr)&_fExtValue;
-
- fEntitySpecifier = &fEntity;
-
- CRLI recipientRLI(dirName,extType);
- OCEPackRLI((RLI*)&recipientRLI,(PackedRLI*)fEntity.fRLI,sizeof(CPackedRLI));
-
- fEntity.SetType(kUserRecTypeNum);
- fEntity.SetName(name);
-
- fExtType = extType;
- _fExtValue = extValue;
- fExtSize = _fExtValue.Length();
- }
-
-
-
- //-------------------------------------------------------------------------------------------
- CDSSpec::CDSSpec(CRecordName& name,StringPtr dirName, OSType extType,StringPtr extValue )
- {
- fExtValue = (Ptr)&_fExtValue;
-
- fEntitySpecifier = &fEntity;
-
- CRLI recipientRLI(dirName,extType);
- OCEPackRLI((RLI*)&recipientRLI,(PackedRLI*)fEntity.fRLI,sizeof(CPackedRLI));
-
- fEntity.SetType(kUserRecTypeNum);
- fEntity.SetName(name);
-
- fExtType = extType;
- _fExtValue = extValue;
- fExtSize = _fExtValue.Length();
- }
-
-
- //-----------------------------------------------------------------------------------------
- CDSSpec::CDSSpec(StringPtr name,CDirectoryName& dirName,OSType extType,StringPtr extValue)
- {
- fExtValue = (Ptr)&_fExtValue;
-
- fEntitySpecifier = &fEntity;
-
- CRLI recipientRLI(dirName,extType);
- OCEPackRLI((RLI*)&recipientRLI,(PackedRLI*)fEntity.fRLI,sizeof(CPackedRLI));
-
- fEntity.SetType(kUserRecTypeNum);
- fEntity.SetName(name);
-
- fExtType = extType;
- _fExtValue = extValue;
- fExtSize = _fExtValue.Length();
- }
-
-
-
- //-------------------------------------------------------------------------------------------
- CDSSpec::CDSSpec(OCEPackedRecipient* packedRecipient )
- {
- RecordID rid;
- DSSpec dsspec;
-
- OCEUnpackDSSpec((PackedDSSpec*)packedRecipient,&dsspec,&rid);
-
- fEntitySpecifier = &fEntity;
-
- // We copy into this
-
- fEntity = &rid; // copy
-
- fExtType = dsspec.extensionType;
- fExtSize = dsspec.extensionSize;
-
- _fExtValue = (RString*)dsspec.extensionValue; // assumption of string.
- }
-
-
-
-